{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from PIL import Image\n",
    "\n",
    "import os\n",
    "\n",
    "import glob\n",
    "\n",
    "path = os.path.join('test', '*.gif')  ##拼接路径\n",
    " \n",
    "files = glob.glob(path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "def RecolorFiles():  \n",
    "    for item in files:  \n",
    "        im = Image.open(item)\n",
    "        item_r = os.path.splitext(item)[0] + \".jpg\"\n",
    "        bg = Image.new(\"RGB\", im.size, (255,255,255))\n",
    "        bg.paste(im,im)\n",
    "        out = bg.resize((224,224))\n",
    "        out.save(item_r,format=\"jpeg\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "RecolorFiles()  "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [Root]",
   "language": "python",
   "name": "Python [Root]"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
